package fr.kirin.logger.model.gui;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import fr.kirin.logger.model.DefaultLoggerTreeModel;
import fr.kirin.logger.model.DefaultLoggerTreeModel.InfoBean;

public class LoggerCellRenderer extends DefaultTreeCellRenderer {

	
	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		
		
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
		DefaultLoggerTreeModel.InfoBean bean = (InfoBean) node.getUserObject();
		
		if(leaf){
			Icon icon = bean.getLevel().getIcon();
			if(icon != null)
				setLeafIcon(icon);
			else
				setLeafIcon(getDefaultLeafIcon());
		}
		 super.getTreeCellRendererComponent(tree, value,	 sel, expanded,
					leaf, row, hasFocus);
		if(leaf){
			
			setForeground(bean.getLevel().getColor());
			Icon icon = bean.getLevel().getIcon();
			if(icon != null)
				setLeafIcon(icon);
			else
				setLeafIcon(getDefaultLeafIcon());
			
		}
		
		
		 return this;
	}
	
	
}
